﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.Materials;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week2.Mainplan_CRUD
{
    public class GetItemInfoDataHander : IRequestHandler<GetItemInfoDataCommand, Result>
    {
        /// <summary>
        /// 获取物料表数据
        /// </summary>
        /// <param name="itemInfoRepository"></param>
        public GetItemInfoDataHander(IBaseRepository<ItemInfo> itemInfoRepository)
        {
            ItemInfoRepository = itemInfoRepository;
        }

        public IBaseRepository<ItemInfo> ItemInfoRepository { get; set; }
        public async Task<Result> Handle(GetItemInfoDataCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCodes.Search};
            var sql = "select * from ItemInfo;";
            var list = ItemInfoRepository.GetAll(sql).ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
